/******************************************************************************* 
 * Copyright (C) 2012-2015 Microfountain Technology, Inc. All Rights Reserved. 
 * 
 * Unauthorized copying of this file, via any medium is strictly prohibited.   
 * Proprietary and confidential
 * 
 * Last Modified: 2015-9-17 12:05:36
 ******************************************************************************/
package cn.com.xy.sms.sdk.db.entity.pubinfo;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import cn.com.xy.sms.sdk.Iservice.OnlineUpdateCycleConfigInterface;
import cn.com.xy.sms.sdk.constant.Constant;
import cn.com.xy.sms.sdk.db.DBManager;
import cn.com.xy.sms.sdk.db.XyCursor;
import cn.com.xy.sms.sdk.db.base.BaseManager;
import cn.com.xy.sms.sdk.db.entity.IccidInfo;
import cn.com.xy.sms.sdk.db.entity.IccidInfoManager;
import cn.com.xy.sms.sdk.db.entity.NetQueryTimeManager;
import cn.com.xy.sms.sdk.db.entity.SysParamEntityManager;
import cn.com.xy.sms.sdk.dex.DexUtil;
import cn.com.xy.sms.sdk.iccid.IccidLocationUtil;
import cn.com.xy.sms.sdk.log.LogManager;
import cn.com.xy.sms.sdk.net.NetUtil;
import cn.com.xy.sms.sdk.queue.SdkTaskQueue;
import cn.com.xy.sms.sdk.queue.TaskInfo;
import cn.com.xy.sms.sdk.service.pubInfo.PubInfoNetService;
import cn.com.xy.sms.sdk.service.pubInfo.PubInfoService;
import cn.com.xy.sms.sdk.threadpool.SmartSmsThreadPoolManager;
import cn.com.xy.sms.sdk.util.JsonUtil;
import cn.com.xy.sms.sdk.util.RecordFunctionUtil;
import cn.com.xy.sms.sdk.util.StringUtils;
import cn.com.xy.sms.util.SdkCallBack;

/* SDK-397 huangzhiqiang 20160526 start */
import cn.com.xy.sms.sdk.action.AbsSdkDoAction;
import cn.com.xy.sms.sdk.util.DuoquUtils;
/* SDK-397 huangzhiqiang 20160526 end */

/*SDK-633 hewengao 20161009 start*/
import android.os.Process;
/*SDK-633 hewengao 20161009 end*/
import cn.com.xy.sms.util.UUIDUtils;
import cn.com.xy.sms.sdk.util.ConversationManager;

public class PubInfoManager {

    public static final String PUB_INFO_TABLE_NAME = "tb_public_info";
    public static final String PUB_MENU_INFO_TABLE_NAME = "tb_public_menu_info";
    public static final String PUB_NUM_INFO_TABLE_NAME = "tb_public_num_info";

    public static final String DROP_TABLE_PUBLIC_INFO = " DROP TABLE IF EXISTS " + PUB_INFO_TABLE_NAME;
    public static final String DROP_TABLE_PUBLIC_MENU_INFO = " DROP TABLE IF EXISTS " + PUB_MENU_INFO_TABLE_NAME;
    public static final String DROP_TABLE_PUBLIC_NUM_INFO = " DROP TABLE IF EXISTS " + PUB_NUM_INFO_TABLE_NAME;

    public static final String ADD_CLASSIFY_CODE = "ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN classifyCode TEXT";
    public static final String ADD_CORP_LEVEL = " ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN corpLevel INTEGER default 0";

    public static final String ADD_LOADTIME = " ALTER TABLE " + PUB_NUM_INFO_TABLE_NAME + " ADD COLUMN lastloadtime LONG default 0";
    public static final String ADD_ISRULENUM = " ALTER TABLE " + PUB_NUM_INFO_TABLE_NAME + " ADD COLUMN isrulenum INTEGER default 0";
    /* SDK-397 huangzhiqiang 20160524 start */
    public static final String ADD_IS_USE = " ALTER TABLE " + PUB_NUM_INFO_TABLE_NAME + " ADD COLUMN isuse LONG default 0";
    // nameType 名称类型(0:企业名称  1:签名)
    public static final String ADD_NAME_TYPE = " ALTER TABLE " + PUB_NUM_INFO_TABLE_NAME + " ADD COLUMN nameType INTEGER default 0";
    /* SDK-397 huangzhiqiang 20160524 end */
    
    /* SDK-524 zhaojiangwei 20160708 start */
    public static final String ADD_COLUMN_RID = "ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN rid TEXT";
    public static final String ADD_COLUMN_LOGOTYPE = " ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN logoType TEXT";
    /* SDK-524 zhaojiangwei 20160708 end */

    /* SDK-631 huangzhiqiang 20161008 start */
    public static final String ADD_COLUMN_SCALE = "ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN scale INTEGER default 0";
    /* SDK-631 huangzhiqiang 20161008 end */
    
    /* SDK-704 zhaojiangwei 20161217 start */
    public static final String ADD_COLUMN_BACKCOLOR = "ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN backColor TEXT";
    public static final String ADD_COLUMN_BACKCOLOREND = "ALTER TABLE " + PUB_INFO_TABLE_NAME + " ADD COLUMN backColorEnd TEXT";
    /* SDK-704 zhaojiangwei 20161217 end */
    
    public static String getCreatePubInfoTableSql() {
        return " create table  if not exists " + PUB_INFO_TABLE_NAME + " (id INTEGER PRIMARY KEY,"
                + " pubId INTEGER not null unique, pubName TEXT not null, pubType TEXT,"
                + " classifyCode TEXT, weiXin TEXT, weiBoName TEXT, weiBoUrl TEXT, introduce TEXT,"
                + " address TEXT, faxNum TEXT, webSite TEXT, moveWebSite TEXT, versionCode TEXT,"
                + " email TEXT, parentPubId int, slogan TEXT, rectLogoName TEXT,"
                + " circleLogoName TEXT, extend TEXT, hasmenu int, loadMenuTime long,"
                + " updateInfoTime long default 0, corpLevel INTEGER default 0,"
                + " rid TEXT, logoType  TEXT,"
                /* SDK-631 huangzhiqiang 20161008 start */
                + " scale INTEGER default 0,"
                /* SDK-631 huangzhiqiang 20161008 end */
                /* SDK-704 zhaojiangwei 20161217 start */
                 + " backColor TEXT, backColorEnd TEXT"
                /* SDK-704 zhaojiangwei 20161217 end */
                + ")";
    }

    public static String getCreatePubmenuInfoTableSql() {
        return "create table  if not exists " + PUB_MENU_INFO_TABLE_NAME + " (id INTEGER PRIMARY KEY,"
                + " menuCode text not null, pubId INTEGER, menuName text not null,"
                + " menuType text not null, sendTo text, sp text , menuDesc text , sms text,"
                + " url text, phoneNum text, actionData text, extend text)";
    }

    public static String getCreatePubNumInfoTableSql() {
        /* SDK-397 huangzhiqiang 20160524 start */
        return "create table  if not exists " + PUB_NUM_INFO_TABLE_NAME + " (id INTEGER PRIMARY KEY,"
                + " pubId INTEGER not null, num text not null, purpose text , areaCode text not null,"
                + " ptype int default 1, main INTEGER default 0, communication INTEGER default 0,"
                + " isfull INTEGER default 0, minLen INTEGER default 0, maxLen INTEGER default 0,"
                + " len INTEGER default 0, ntype text, extend text, lastloadtime LONG default 0,"
                + " isuse LONG default 0, isrulenum INTEGER default 0, nameType INTEGER default 0)";
        /* SDK-397 huangzhiqiang 20160524 end */
    }

    /* SDK-397 huangzhiqiang 20160524 start */
    // 名称类型-签名
    public static final int NAME_TYPE_SIGN = 1;
    /* SDK-397 huangzhiqiang 20160524 end */

    /***
     * 验证号码有效性
     * 
     * @param pn
     *            源号码
     * @param p
     *            规则号码
     * @param len
     *            固定长
     * @param maxLen
     *            最大长
     * @param minLen
     *            最小长
     * @param pt
     *            类型
     * @return
     */
    public static boolean validPhone(String pn, String p, int len, int maxLen, int minLen, String pt) {

        int idx = p.indexOf("*");
        if (idx > -1) {
            String s1 = p.substring(0, idx);

            String s2 = p.substring(idx + 1);
            if (!pn.startsWith(s1) || !pn.endsWith(s2)) {
                return false;
            }
            int plen = s1.length() + s2.length();
            int nlen = pn.length();
            if (len > 0) {
                if (plen + len != nlen)
                    return false;
            } else {
                if (maxLen > 0 && (nlen > plen + maxLen))
                    return false;
                if (minLen > 0 && (nlen < plen + minLen))
                    return false;
            }
            if ("sj".equals(pt)) {
                if (!StringUtils.sj(pn)) {
                    return false;
                }
            }
        } else {
            return false;
        }
        return true;

    }

    private static HashMap<String, String> queryPubIdHasRuleNum(String sourceNum, String areaCode, int type) {
        // int res =-1;
        SQLiteDatabase sdb = null;
        try {
            // long st = System.currentTimeMillis();
            // long ed =System.currentTimeMillis();
            sdb = DBManager.getSQLiteDatabase();
            /* SDK-397 huangzhiqiang 20160524 start */
            // 开头匹配
            String sql = "SELECT pubId,minLen,maxLen,len,ntype,num,areaCode,purpose,extend,nameType from tb_public_num_info where num like '%*' and '" + sourceNum + "' like  substr(num,1,length(num)-1) || '%'  and ptype = '" + type + "'";
            /* SDK-397 huangzhiqiang 20160524 end */
            boolean isALL = "CN".equals(areaCode);
            if (isALL)
                sql = sql + " and areaCode = 'CN;'";

            /*SDK-501 zhaojiangwei 20160623 start*/
            HashMap<String, String> resMap = queryPubIdHasRuleNum(sdb, sourceNum, sql + " order by lastloadtime desc, length(num) desc ", areaCode, type);
            /*SDK-501 zhaojiangwei 20160623 end*/
            
            return resMap;
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryPubIdHasRuleNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            DBManager.close(sdb);
        }
        return null;
    }

    /**
     * 加载有规则的号码缓存
     */
    @SuppressWarnings("resource")
    public static HashMap<String, String> queryPubIdHasRuleNum(SQLiteDatabase db, String sourceNum, String sql, String areaCode, int numType) {
        Cursor cur = null;
        int pubId = -1;
        String purpose = null;
        String extend = null;
        /* SDK-397 huangzhiqiang 20160526 start */
        int nameType = 0;
        String num = null;
        /* SDK-397 huangzhiqiang 20160526 end */
        HashMap<String, String> res = null;
        try {
            // LogManager.i("duoqu_test","sourceNum: "+sourceNum);
            // LogManager.i("duoqu_test","sql: "+sql);
            cur = db.rawQuery(sql, null);
            if (cur != null && cur.getCount() > 0) {
                int minLen = 0;
                int maxLen = 0;
                int len = 0;
                String pt = null;
                String code = null;

                while (cur.moveToNext()) {
                    minLen = cur.getInt(cur.getColumnIndex("minLen"));
                    maxLen = cur.getInt(cur.getColumnIndex("maxLen"));
                    len = cur.getInt(cur.getColumnIndex("len"));
                    pt = cur.getString(cur.getColumnIndex("ntype"));
                    num = cur.getString(cur.getColumnIndex("num"));
                    code = cur.getString(cur.getColumnIndex("areaCode"));

                    // LogManager.i("duoqu_test",
                    // "rnum: "+rnum+" sourceNum: "+sourceNum+" code: "+code+" maxlen: "+maxLen+" minLen:"+minLen+" len: "+len);
                    if (validPhone(sourceNum, num, len, maxLen, minLen, pt)) {
                        if (code.indexOf(areaCode) != -1) {
                            pubId = cur.getInt(cur.getColumnIndex("pubId"));
                            purpose = cur.getString(cur.getColumnIndex("purpose"));
                            extend = cur.getString(cur.getColumnIndex("extend"));
                            /* SDK-397 huangzhiqiang 20160526 start */
                            nameType = cur.getInt(cur.getColumnIndex("nameType"));
                            /* SDK-397 huangzhiqiang 20160524 end */
                            asyncInsertRuleMatchNum(pubId, areaCode + ";", sourceNum, numType, purpose, extend, nameType);
                            res = new HashMap<String, String>();
                            res.put("pubId", String.valueOf(pubId));
                            res.put("purpose", purpose);
                            res.put("areaCode", code);
                            res.put("extend", extend);
                            /* SDK-397 huangzhiqiang 20160526 start */
                            res.put("nameType", String.valueOf(nameType));
                            res.put("num", num);
                            /* SDK-397 huangzhiqiang 20160526 end */
                            return res;
                        }
                        if (code.indexOf("CN") != -1) {
                            pubId = cur.getInt(cur.getColumnIndex("pubId"));
                            purpose = cur.getString(cur.getColumnIndex("purpose"));
                            extend = cur.getString(cur.getColumnIndex("extend"));
                            /* SDK-397 huangzhiqiang 20160526 start */
                            nameType = cur.getInt(cur.getColumnIndex("nameType"));
                            /* SDK-397 huangzhiqiang 20160526 end */
                        }
                    }
                }
            }
            if (pubId > 0) {
                /* SDK-397 huangzhiqiang 20160526 start */
                asyncInsertRuleMatchNum(pubId, "CN;", sourceNum, numType, purpose, extend, nameType);
                /* SDK-397 huangzhiqiang 20160526 end */
            }
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryPubIdHasRuleNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            DBManager.closeCursor(cur);
        }
        if (pubId != -1) {
            res = new HashMap<String, String>();
            res.put("pubId", String.valueOf(pubId));
            res.put("purpose", purpose == null ? "" : purpose);
            res.put("areaCode", "CN");
            res.put("extend", extend == null ? "" : extend);
            /* SDK-397 huangzhiqiang 20160526 start */
            res.put("nameType", String.valueOf(nameType));
            res.put("num", num);
            /* SDK-397 huangzhiqiang 20160526 end */
            return res;
        }
        return res;
    }

    /**
     * 查询企业资料ID,依据号码和归属地。
     * 
     * @param num
     * @param areaCode
     * @param type
     * @return
     */
    public static HashMap<String, String> queryPubIdByNum(final String num, String areaCode, int type) {
        XyCursor cur = null;
        int pubId = -1;
        String purpose = null;
        String returnAreaCode = null;
        String extend = null;
        int nameType = 0; // 名称类型(0:企业名称  1:签名)
        HashMap<String, String> resMap = null;
        try {
            boolean isRuleMatch = false;
            /* SDK-397 huangzhiqiang 20160524 start */
            String sql = "SELECT pubId,purpose,extend,nameType from tb_public_num_info where num = '" + num + "' and ptype = '" + type + "' and areaCode LIKE '%" + areaCode + "%'";
            /* SDK-397 huangzhiqiang 20160524 end */
            cur = DBManager.rawQuery(sql, null);
            if (cur != null && cur.getCount() > 0) {
                // int pubIdIndex = cur.getColumnIndex("pubId");
                while (cur.moveToNext()) {
                    pubId = cur.getInt(cur.getColumnIndex("pubId"));
                    purpose = cur.getString(cur.getColumnIndex("purpose"));
                    extend = cur.getString(cur.getColumnIndex("extend"));
                    /* SDK-397 huangzhiqiang 20160524 start */
                    nameType = cur.getInt(cur.getColumnIndex("nameType"));
                    /* SDK-397 huangzhiqiang 20160524 end */
                    returnAreaCode = areaCode;
                    break;
                }
            } else {
                XyCursor.closeCursor(cur, true);

                if (!"CN".equalsIgnoreCase(areaCode)) {
                    /* SDK-397 huangzhiqiang 20160524 start */
                    sql = "SELECT pubId,purpose,extend,nameType from tb_public_num_info where num = '" + num + "' and ptype = '" + type + "' and areaCode LIKE '%CN%'";
                    /* SDK-397 huangzhiqiang 20160524 end */
                    cur = DBManager.rawQuery(sql, null);
                    if (cur != null && cur.getCount() > 0) {
                        while (cur.moveToNext()) {
                            pubId = cur.getInt(cur.getColumnIndex("pubId"));
                            purpose = cur.getString(cur.getColumnIndex("purpose"));
                            extend = cur.getString(cur.getColumnIndex("extend"));
                            /* SDK-397 huangzhiqiang 20160524 start */
                            nameType = cur.getInt(cur.getColumnIndex("nameType"));
                            /* SDK-397 huangzhiqiang 20160524 end */
                            returnAreaCode = "CN";
                            break;
                        }
                    } else {
                        resMap = queryPubIdHasRuleNum(num, areaCode, type);
                        isRuleMatch = true;
                    }
                } else {
                    resMap = queryPubIdHasRuleNum(num, areaCode, type);
                    isRuleMatch = true;
                }

            }

            if (pubId > 0 && !isRuleMatch) {
                // 查询到pubid，更新num 表号码为使用过
                updateNumIsUse(num, returnAreaCode);
            }

            if (resMap != null && isRuleMatch) {

                resMap.put("ruleMatch", "");
                return resMap;
            }

        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryPubIdByNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cur, true);
        }
        if (pubId > -1) {
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("pubId", String.valueOf(pubId));
            if (!StringUtils.isNull(purpose)) {
                map.put("purpose", purpose);
            }
            if (!StringUtils.isNull(returnAreaCode)) {
                map.put("areaCode", returnAreaCode);
            }
            if (!StringUtils.isNull(extend)) {
                map.put("extend", extend);
            }
            /* SDK-397 huangzhiqiang 20160526 start */
            map.put("nameType", String.valueOf(nameType));
            map.put("num", num);
            /* SDK-397 huangzhiqiang 20160526 end */
            return map;
        }
        return null;
    }

    public static JSONObject queryPubInfoByNum(String num, String areaCode, int type) {
        JSONObject pubInfo = null;
        try {
            HashMap<String, String> res = queryPubIdByNum(num, areaCode, type);
            if (res == null) {
                return null;
            }
            int pubId = Integer.valueOf(res.get("pubId"));
            if (pubId != -1) {
                pubInfo = queryPubInfoByPubId(pubId);
                if (pubInfo == null) {
                    return null;
                }
                pubInfo.put("purpose", res.get("purpose"));
                
                /*SDK-524 zhaojiangwei 20160708 start */
                pubInfo.put("rid", res.get("rid"));
                pubInfo.put("logoType", res.get("logoType"));
                /*SDK-524 zhaojiangwei 20160708 end */
                
                pubInfo.put("extend", res.get("extend"));
                /* SDK-397 huangzhiqiang 20160526 start */
                pubInfo.put("nameType", res.get("nameType"));
                pubInfo.put("num", num);
                /* SDK-397 huangzhiqiang 20160526 end */
                String name = pubInfo.optString("pubName");
                if (!StringUtils.isNull(name)) {
                    // 查看完，更新查看时间
                    updateQueryTime(pubInfo);
                }

            }
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryPubInfoByNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
        return pubInfo;
    }

    public static JSONObject queryPubInfoByPubId(int pubId) {
        XyCursor cursor = null;
        JSONObject jsonObject = null;
        try {
            String[] fieldArr = new String[] { "id", "pubId", "pubName", "pubType", "classifyCode", "weiXin",
                    "weiBoName", "weiBoUrl", "introduce", "address", "faxNum", "webSite", "versionCode", "email",
                    "parentPubId", "slogan", "rectLogoName", "circleLogoName", "extend", "hasmenu", "loadMenuTime",
                    "updateInfoTime", "moveWebSite", "corpLevel", "rid", "logoType", 
                    /* SDK-631 huangzhiqiang 20161008 start */
                    "scale", 
                    /* SDK-631 huangzhiqiang 20161008 end */
                    /* SDK-704 zhaojiangwei 20161217 start */
                    "backColor", "backColorEnd"
                    /* SDK-704 zhaojiangwei 20161217 end */
                    };
            cursor = DBManager.query(PUB_INFO_TABLE_NAME, fieldArr, "pubId = ? ", new String[] { pubId + "" });
            jsonObject = BaseManager.loadSingleDataFromCursor(fieldArr, cursor);
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryPubInfoByPubId: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cursor, true);
        }
        return jsonObject;
    }

    public static JSONArray queryMenuByNum(final String num, final String areaCode, final int type, final boolean excludeCN, final String simIccid, final String cnum, int simIndex, final SdkCallBack callBack) {

        try {
            if (excludeCN && "CN".equals(areaCode)) {
                return null;
            }
            final HashMap<String, String> res = queryPubIdByNum(num, areaCode, type);
            if (res == null) {
                queryPubInfoRequestAsync(areaCode, simIccid, num, cnum, type, false, callBack);
                return null;
            }

            /* SDK-397 huangzhiqiang 20160526 start */
            if (!checkIsEffectivePubInfoIfNameTypeIsSign(new JSONObject(res))) {
                return null;
            }
            /* SDK-397 huangzhiqiang 20160526 end */

            String currentDataCode = res.get("areaCode");
             if ("CN".equals(currentDataCode) && !res.containsKey("ruleMatch")) {
                // 当前数据是全国数据。且不是规则匹配的数据。
                /*SDK-495 zhaojiangwei 20160620 start*/
                // if (!StringUtils.isNull(areaCode) && !"CN".equals(areaCode)) {
                if (!StringUtils.isNull(areaCode)) {
                /*SDK-495 zhaojiangwei 20160620 end*/
                    queryPubInfoRequestAsync(areaCode, simIccid, num, cnum, type, true, new SdkCallBack() {
                        @Override
                        public void execute(Object... obj) {
                            if (callBack != null && obj != null && obj.length == 2) {
                                String pubId = obj[1] == null ? null : obj[1].toString();
                                if (pubId!=null && !pubId.equals(res.get("pubId"))) {
                                    callBack.execute(obj[0]);
                                }
                            }
                        }
                    });
                }
                if (excludeCN) {
                    return null;
                }
            }

            HashMap<String, String> pubInfoMap = res;
            // 区域编码对应的iccid，进行进行菜单数据的运营商校验时，当没有传递iccid参数及index参数时需
            // 要根据这个参数来判断菜单数据属于哪张sim卡
            String areaIccid = null;

            boolean needComparePubNumOperator = "true".equals(SysParamEntityManager.getStringParam(Constant.getContext(), Constant.COMPARE_PUBNUM_OPERATOR));
            // boolean iccidValid = !StringUtils.isNull(simIccid) &&
            // simIccid.length() == 20;
            boolean hasIccidData = IccidLocationUtil.getIccidAreaCodeMap().size() > 0;

            // iccid有效、需要对比公众号运营商且当前查询的省份不是全国时才需要进行菜单数据的运营商校验
            if (hasIccidData && needComparePubNumOperator && !"CN".equals(currentDataCode)) {
                int numOperator = getPubInfoOperatorNum(pubInfoMap);
                if (numOperator != -1) {
                    String result = getAreaCodeByOperator(numOperator, simIccid, areaCode, simIndex);
                    if (result != null && result.startsWith("CN")) {
                        // 无法获取sim卡iccid的运营商编号或当前运营商编号与接入码所属运营商编号不匹配，使用全国数据
                        pubInfoMap = queryPubIdByNum(num, result, type);
//                        queryPubInfoByPubId()

                        // 无全国数据，请求全国菜单数据
                        if (pubInfoMap == null || !pubInfoMap.containsKey("pubId")) {
                            queryPubInfoRequestAsync("CN", simIccid, num, cnum, type, false, callBack);
                            return null;
                        }
                    } else if (result!=null && result.contains("_")) {
                        String[] iccidInfoArr = result.split("_");
                        if (iccidInfoArr.length > 1) {
                            areaIccid = iccidInfoArr[1];
                        }
                    }
                }
            }

            String pubId = pubInfoMap.get("pubId");
            JSONObject jsonObject = queryPubInfoByPubId(Integer.parseInt(pubId));
            String rid = "";
            String versionCode = "";
            if (jsonObject!=null) {
            	 versionCode = jsonObject.optString("versionCode");
            	 rid = jsonObject.optString("rid");
			}
            //统计菜单展现次数接口
            JSONArray menuInfoJsonArr = queryMenuDataAction(pubId, num, versionCode, rid);
            if (menuInfoJsonArr != null){
            	/*SDK-774 songzhirong 20170427 start */
                String uuid = UUIDUtils.uniqId();
                ConversationManager.saveLogIn(uuid,"cn.com.xy.sms.sdk.db.entity.pubinfo.PubInfoManager", "queryMenuByNum",  num,  pubId,  rid, versionCode,currentDataCode,type, excludeCN,  simIccid, cnum,  simIndex);
            	/*SDK-774 songzhirong 20170427 end */

                String  spliceString = pubId + "_" + versionCode;
                SdkTaskQueue.addTask(new TaskInfo(12, "state",  String.valueOf(RecordFunctionUtil.MENU_STATE)));//菜单标记记录
                SdkTaskQueue.addTask(new TaskInfo(11, "phoneNum",  String.valueOf(num), "companyNum",  spliceString, "functionMode",  Constant.MENU_SHOW_TIMES));
                
                // 区域编码对应的iccid不为空时添加到菜单Json数据，用于判断该菜单数据属于哪张sim卡
                if (!StringUtils.isNull(areaIccid) && menuInfoJsonArr.length() > 0) {
                    JSONObject menuJsonData = menuInfoJsonArr.getJSONObject(0);
                    menuJsonData.put("iccid", areaIccid);
                }
            	/*SDK-774 songzhirong 20170427 start */
                ConversationManager.saveLogOut(uuid,"cn.com.xy.sms.sdk.db.entity.pubinfo.PubInfoManager", "queryMenuByNum", num,  pubId,  rid, versionCode,currentDataCode,type, excludeCN,  simIccid, cnum,  simIndex);
            	/*SDK-774 songzhirong 20170427 end */

            }
            return menuInfoJsonArr;
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager queryMenuByNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
        return null;
    }

    private static void queryPubInfoRequestAsync(final String areaCode, final String simIccid, final String phoneNum, final String cnum, final int numType, final boolean hasData, final SdkCallBack callBack) {
        try {
            // 网络请求
            final String _numType = String.valueOf(numType);
            /*SDK-628 zhaojiangwei 20160929 start */
            SmartSmsThreadPoolManager.pubInfoPool.execute(new Runnable() {
            /*SDK-628 zhaojiangwei end start */
                @Override
                public void run() {
                    try {
                        /*SDK-633 hewengao 20161009 start*/
                        SmartSmsThreadPoolManager.setThreadNameAndPriority(SmartSmsThreadPoolManager.TNAME_QUERY_PUBINFO, Process.THREAD_PRIORITY_BACKGROUND);
                        /*SDK-633 hewengao 20161009 end*/
                        if (NetUtil.isEnhance()) {
                            // 单个查询
                            PubInfoNetService.queryPubInfoRequest(false, phoneNum, cnum, areaCode, simIccid, _numType, callBack, PubInfoNetService.CB_TYPE_MENU, false, hasData, false);
                        } else if (callBack != null) {
                            callBack.execute();
                        }
                        /*SDK-613 hewengao/20160908 start*/
                        if (NetUtil.checkAccessNetWork(2)) {
                            PubInfoService.checkPubInfoUpdate(areaCode, simIccid);
                        }
                        /*SDK-613 hewengao/20160908 end*/
                    } catch (Throwable e) {
                        LogManager.w(Constant.TAG, e.getMessage(), e);
                    }
                }
            });
        } catch (Throwable e) {
            LogManager.w(Constant.TAG, "PubInfoManager queryPubInfoRequestAsync ", e);
        }
    }

    public static void savaPubInfo(JSONObject pubInfo) {
        try {
            if (pubInfo == null)
                return;
            
            String corpLevel = pubInfo.optString("corpLevel");
            ContentValues values = BaseManager.getContentValues(null, "pubId", pubInfo.optString("pubId"), "pubName",
                    pubInfo.optString("pubName"), "pubType", pubInfo.optString("pubType"), "classifyCode",
                    pubInfo.optString("classifyCode"), "weiXin", pubInfo.optString("weiXin"), "weiBoName",
                    pubInfo.optString("weiBoName"), "weiBoUrl", pubInfo.optString("weiBoUrl"), "introduce",
                    pubInfo.optString("introduce"), "address", pubInfo.optString("address"), "faxNum",
                    pubInfo.optString("faxNum"), "webSite", pubInfo.optString("webSite"), "versionCode",
                    pubInfo.optString("versionCode"), "email", pubInfo.optString("email"), "parentPubId",
                    pubInfo.optString("parentPubId"), "slogan", pubInfo.optString("slogan"), "rectLogoName",
                    pubInfo.optString("rectLogoName"), "circleLogoName", pubInfo.optString("circleLogoName"), "extend",
                    pubInfo.optString("extend"), "hasMenu", pubInfo.optString("hasMenu"), "loadMenuTime",
                    pubInfo.optString("loadMenuTime"), "moveWebSite", pubInfo.optString("moveWebSite"), "corpLevel",
                    /* SDK-476 songzhirong 2016-06-07 start*/
                    (StringUtils.isNull(corpLevel) ? "0" : corpLevel), "updateInfoTime",
                    String.valueOf(System.currentTimeMillis()),
                    /* SDK-476 songzhirong 2016-06-07 end*/
                    /* SDK-524 zhaojiangwei start */
                    "rid", pubInfo.optString("rid"), "logoType", pubInfo.optString("logoType"),
                    /* SDK-524 zhaojiangwei end */
                    /* SDK-631 huangzhiqiang 20161008 start */
                    "scale", pubInfo.optString("scale", "0"),
                    /* SDK-631 huangzhiqiang 20161008 end */
                    /* SDK-704 20161217 zhaojiangwei start */
                    "backColor", pubInfo.optString("backColor"), "backColorEnd", pubInfo.optString("backColorEnd")
                    /* SDK-704 20161217 zhaojiangwei end */
                    );
                   
            long flag = DBManager.update(PUB_INFO_TABLE_NAME, values, "pubId = ?", new String[] { pubInfo.optString("pubId") });
            if (flag < 1) {
                flag = DBManager.insert(PUB_INFO_TABLE_NAME, values);
            }
            /*SDK-439 songzhirong 20160518 start*/
            deletePubNumInfoByPubId(pubInfo.optString("pubId"));
            JSONArray pubNumInfolist = pubInfo.optJSONArray("pubNumInfolist");
            if (pubNumInfolist != null && pubNumInfolist.length() > 0) {
                int size = pubNumInfolist.length();
                for (int i = 0; i < size; i++) {
                    JSONObject pubNumInfo = pubNumInfolist.optJSONObject(i);
                    savePubNumInfo(pubNumInfo);
                }
            }

            deletePubMenuInfo(pubInfo.optString("pubId"));
            JSONArray pubMenuInfolist = pubInfo.optJSONArray("pubMenuInfolist");
            if (pubMenuInfolist != null && pubMenuInfolist.length() > 0) {
                int size = pubMenuInfolist.length();
                for (int i = 0; i < size; i++) {
                    JSONObject pubMenuInfo = pubMenuInfolist.optJSONObject(i);
                    savePubMenuInfo(pubMenuInfo);
                }
            }
            /*SDK-439 songzhirong 20160518 end*/
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager savaPubInfo: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    public static void updateQueryTime(JSONObject pubInfo) {
        try {
            if (pubInfo == null)
                return;

            ContentValues values = new ContentValues();
            values.put("loadMenuTime", System.currentTimeMillis());
//            values.put("updateInfoTime", System.currentTimeMillis());
            DBManager.update(PUB_INFO_TABLE_NAME, values, "pubId = ?", new String[] { pubInfo.optString("pubId") });
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager updateQueryTime: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    public static void savePubMenuInfo(JSONObject pubMenuInfo) {
        try {
            if (pubMenuInfo == null)
                return;
            JSONArray secondmenuArray = pubMenuInfo.optJSONArray("secondmenu");
            if (secondmenuArray != null && secondmenuArray.length() > 0) {
                saveSinglePubMenuInfo(pubMenuInfo);
                int size = secondmenuArray.length();
                for (int i = 0; i < size; i++) {
                    JSONObject singlePubMenuInfo = secondmenuArray.getJSONObject(i);
                    saveSinglePubMenuInfo(singlePubMenuInfo);
                }
            } else {
                saveSinglePubMenuInfo(pubMenuInfo);
            }

        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager savePubMenuInfo: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    public static void saveSinglePubMenuInfo(JSONObject pubMenuInfo) {
        try {
            if (pubMenuInfo == null)
                return;

            /*
             * ContentValues values = BaseManager.getContentValues(null,
             * "menuCode",pubMenuInfo.optString("menuCode"),
             * "pubId",pubMenuInfo.optString("pubId"),
             * "menuName",pubMenuInfo.optString("name"),
             * "menuType",pubMenuInfo.optString("type"),
             * "extend",pubMenuInfo.optString("extend"),
             * "actionData",pubMenuInfo.optString("action_data"));
             * DBManager.insert(PUB_MENU_INFO_TABLE_NAME, values);
             */

            ContentValues values = BaseManager.getContentValues(null, "menuCode", pubMenuInfo.optString("menuCode"), "pubId", pubMenuInfo.optString("pubId"), "menuName", pubMenuInfo.optString("name"), "menuType", pubMenuInfo.optString("type"), "extend", pubMenuInfo.optString("extend"), "actionData", pubMenuInfo.optString("action_data"));

            long flag = DBManager.update(PUB_MENU_INFO_TABLE_NAME, values, "pubId = ? and menuCode = ?", new String[] { pubMenuInfo.optString("pubId"), pubMenuInfo.optString("menuCode") });
            /*SDK-550 hewengao 20160719 start*/
            if (flag < 1) {
                flag = DBManager.insert(PUB_MENU_INFO_TABLE_NAME, values);
                LogManager.d(Constant.TAG, "PubInfoManager saveSinglePubMenuInfo insert=", pubMenuInfo.toString());
            } else {
                LogManager.d(Constant.TAG, "PubInfoManager saveSinglePubMenuInfo update=", pubMenuInfo.toString());
            }

        } catch (Throwable e) {
            LogManager.w(Constant.TAG, "PubInfoManager saveSinglePubMenuInfo: ", e);
        }
        /*SDK-550 hewengao 20160719 end*/
    }

    public static void deletePubMenuInfo(String pubId) {
        try {
            DBManager.delete(PUB_MENU_INFO_TABLE_NAME, "pubId = ?", new String[] { pubId });
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager deletePubMenuInfo: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    public static void savePubNumInfo(JSONObject pubNumInfo) {
        try {
            if (pubNumInfo == null)
                return;

            deletePubNumInfoByNum(pubNumInfo);
            /* SDK-397 huangzhiqiang 20160526 start */
            String num = pubNumInfo.optString("num");
            String nameType = pubNumInfo.optString("nameType", "0");
            ContentValues values = BaseManager.getContentValues(null, "pubId", pubNumInfo.optString("pubId"), "num",
                    num, "main", pubNumInfo.optString("main"), "communication", pubNumInfo.optString("communication"),
                    "purpose", pubNumInfo.optString("purpose"), "areaCode", pubNumInfo.optString("areaCode"), "extend",
                    pubNumInfo.optString("extend"), "ptype", pubNumInfo.optString("type"), "isfull",
                    pubNumInfo.optString("isfull"), "minLen", pubNumInfo.optString("minLen"), "maxLen",
                    pubNumInfo.optString("maxLen"), "len", pubNumInfo.optString("len"), "ntype",
                    pubNumInfo.optString("ntype"), "nameType", pubNumInfo.optString("nameType", "0"),
                    /*SDK-501 zhaojiangwei 20160623 start*/
                    "lastloadtime", String.valueOf(System.currentTimeMillis()));
                    /*SDK-501 zhaojiangwei 20160623 end*/
            
            long rs = DBManager.insert(PUB_NUM_INFO_TABLE_NAME, values);
            // 号码信息入库成功并且为签名类型名称时，将当前pubId记录到NumName表
            if (rs > 0 && "1".equals(nameType)) {
                NumNameManager.updateLastNamePubIdByNum(num, pubNumInfo.optInt("pubId"));
            }
            /* SDK-397 huangzhiqiang 20160526 end */

            /* SDK-500 huangzhiqiang 20160621 start */
            // 更新号码联网查询时间并将状态设置为有返回数据
            NetQueryTimeManager.insertOrUpdateNetQueryTime(num, getFirstAreaCode(pubNumInfo.optString("areaCode")), 1);
            /* SDK-500 huangzhiqiang 20160621 end */
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager savePubNumInfo: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    /* SDK-500 huangzhiqiang 20160621 start */
    /**
     * 获取第一个区域信息
     * 
     * @param areaCode
     * @return
     */
    private static String getFirstAreaCode(String areaCode) {
        if (StringUtils.isNull(areaCode)) {
            return "";
        }
        return areaCode.split(";")[0];
    }
    /* SDK-500 huangzhiqiang 20160621 end */

    /* SDK-397 huangzhiqiang 20160526 start */
    /**
     * 发送清除旧的公众号资料缓存通知
     * 
     * @param num 公众号
     */
    public static void sendRemovePubInfoCacheNotification(String num) {
        try {
            if (StringUtils.isNull(num)) {
                return;
            }
            List<String> numList = new ArrayList<String>();
            numList.add(num);
            sendRemovePubInfoCacheNotification(numList);
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG,
                    "PubInfoManager sendRemovePubInfoCacheNotification(String num): ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    /* SDK-723 quyi 20170214 start */
    /**
     * 发送更新旧的公众号资料缓存通知
     * 
     * @param num 公众号
     * @param res 公众号信息
     */
    public static void sendUpdatePubInfoCacheNotification(String num,String res) {
        try {
            if (StringUtils.isNull(num)) {
                return;
            }
            List<String> numList = new ArrayList<String>();
            numList.add(num);
            sendUpdatePubInfoCacheNotification(numList,res);
        } catch (Throwable e) {
            LogManager.e(Constant.TAG,
                    "PubInfoManager sendUpdatePubInfoCacheNotification(String num): ", e);
        }
    }
    /* SDK-723 quyi 20170214 end */

    /**
     * 发送清除旧的公众号资料缓存通知
     * 
     * @param numList 公众号集合
     */
    public static void sendRemovePubInfoCacheNotification(List<String> numList) {
        try {
            if (numList == null || numList.size() < 1) {
                return;
            }
            Map<String, Object> paramsMap = new HashMap<String, Object>();
            paramsMap.put("nums", numList);
            DuoquUtils.getSdkDoAction().onEventCallback(AbsSdkDoAction.SDK_EVENT_REMOVE_PUBINFO_CACHE, paramsMap);
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG,
                    "PubInfoManager sendRemovePubInfoCacheNotification(List<String> list): ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }
    /* SDK-397 huangzhiqiang 20160526 end */

    /* SDK-723 quyi 20170214 start */
    /**
     * 发送更新旧的公众号资料缓存通知
     * 
     * @param numList 公众号集合
     * @param res 公众号信息
     */
    public static void sendUpdatePubInfoCacheNotification(List<String> numList,String res) {
        try {
            if (numList == null || numList.size() < 1) {
                return;
            }
            Map<String, Object> paramsMap = new HashMap<String, Object>();
            paramsMap.put("nums", numList);
            paramsMap.put("result", res);
            DuoquUtils.getSdkDoAction().onEventCallback(AbsSdkDoAction.SDK_EVENT_UPDATE_PUBINFO_CACHE, paramsMap);
        } catch (Throwable e) {
            LogManager.w(Constant.TAG,
                    "PubInfoManager sendUpdatePubInfoCacheNotification(List<String> list): ", e);
        }
    }
    /* SDK-723 quyi 20170214 end */

    /**
     * 删除企业下的所有号码
     * 
     * @param pubId
     */
    public static void deletePubNumInfoByPubId(String pubId) {
        try {
            DBManager.delete(PUB_NUM_INFO_TABLE_NAME, " pubId =? ", new String[] { pubId });
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager deletePubNumInfoByPubId: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    /**
     * 删除同一个号码，相同省份，不同企业Id 的数据。
     * 
     * @param pubNumInfo
     */
    public static void deletePubNumInfoByNum(JSONObject pubNumInfo) {
        try {
            // 删除同一个号码，相同省份，不同企业Id
            String codeArr[] = pubNumInfo.optString("areaCode").split(";");
            for (String code : codeArr) {
                if (StringUtils.isNull(code)) {
                    continue;
                }
                DBManager.delete(PUB_NUM_INFO_TABLE_NAME, "  ptype = ? and num = ? and areaCode like '%" + code + "%'  and pubId !=? ", new String[] { String.valueOf(pubNumInfo.optString("type")), pubNumInfo.optString("num"), pubNumInfo.optString("pubId") });
            }
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager deletePubNumInfoByNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    public static String getJson(String actionType, JSONObject pubMenuInfo) {// actionType=menuType
//        PrintTestLogUtil.printTestLog("getJson", "actionType=" + actionType + " pubMenuInfo=" + pubMenuInfo);
        if (StringUtils.isNull(actionType)) {
            return "";
        }

        StringBuffer sb = new StringBuffer();

        if (!actionType.startsWith("WEB_")) {
            actionType = actionType.toLowerCase();
        }
        if ("reply_sms".equalsIgnoreCase(actionType)) {// 回复短信
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"send_code\":\"" + pubMenuInfo.optString("sms") + "\",");
            sb.append("\"phone\":\"" + pubMenuInfo.optString("sendTo") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("send_sms".equalsIgnoreCase(actionType)) {// 发送短信
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"send_code\":\"" + pubMenuInfo.optString("sms") + "\",");
            sb.append("\"phone\":\"" + pubMenuInfo.optString("sendTo") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("access_url".equalsIgnoreCase(actionType) || "open_url".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"url\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("down_url".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"url\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("download".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"url\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"appName\":\"" + pubMenuInfo.optString("appName") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"extend\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("weibo_url".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"url\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("call_phone".equalsIgnoreCase(actionType) || "call".equalsIgnoreCase(actionType)) {// 打电话
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"phoneNum\":\"" + pubMenuInfo.optString("phoneNum") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("map_site".equalsIgnoreCase(actionType) || "open_map".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"address\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("open_map_list".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"address\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("repayment".equalsIgnoreCase(actionType) || "zfb_repayment".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"appName\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"appDownUrl\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("recharge".equalsIgnoreCase(actionType) || "zfb_recharge".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"sp\":\"" + pubMenuInfo.optString("sp") + "\",");
            sb.append("\"appName\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"appDownUrl\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("open_app".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"appName\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"appDownUrl\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("open_app_url".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"appName\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"appDownUrl\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        } else if ("WEB_TRAFFIC_ORDER".equalsIgnoreCase(actionType)) {
            sb.append("{");
            sb.append("\"type\":\"" + actionType + "\",");
            sb.append("\"sp\":\"" + pubMenuInfo.optString("sp") + "\",");
            sb.append("\"appName\":\"" + pubMenuInfo.optString("extend") + "\",");
            sb.append("\"appDownUrl\":\"" + pubMenuInfo.optString("url") + "\",");
            sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
            sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
            /*SDK-380  hewengao 20160401 start*/
            sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
            /*SDK-380  hewengao 20160401 end*/
            sb.append("}");
        }else{
               /*SDK-380  hewengao 20160401 start*/
             sb.append("{");
             sb.append("\"type\":\"" + actionType + "\",");
             sb.append("\"extend\":\"" + pubMenuInfo.optString("extend") + "\",");
             sb.append("\"url\":\"" + pubMenuInfo.optString("url") + "\",");
             sb.append("\"menuName\":\"" + pubMenuInfo.optString("menuName") + "\",");
             sb.append("\"publicId\":\"" + pubMenuInfo.optString("pubId") + "\",");
             sb.append("\"extendVal\":\"" + pubMenuInfo.optString("extendVal") + "\"");
             sb.append("}");
             /*SDK-380  hewengao 20160401 end*/
        }
     
        return StringUtils.encode(sb.toString());
    }

    public static List<String> getNumsAppearInMonth() {
        XyCursor curResult = null;
        List<String> needUpdateNumList = null;
        // 上次全部更新的时间（全部更新是指本月出现过的号码全部更新）
//        long lastUpdateAllTime = SysParamEntityManager.getLongParam(Constant.KEY_SDK_PUB_UP_TIME, 0, Constant.getContext());
      
        long cyc = DexUtil.getUpdateCycleByType(OnlineUpdateCycleConfigInterface.TYPE_BATCH_PUBLIC_NUM_INFO_UPDATE_CYCLE, Constant.month);
        long updateStartTime = System.currentTimeMillis() - cyc;
        try {
            /* SDK-478 huangzhiqiang 20160628 start */
            String sql = "SELECT DISTINCT pni.num, pi.pubId, pi.versionCode, pni.nameType, nn.name, nn.cmd, nn.ec, nn.mark_time, nn.mark_cmd, nn.mark_ec FROM tb_public_num_info pni JOIN tb_public_info pi ON pi.pubId = pni.pubId LEFT JOIN tb_num_name nn ON nn.num = pni.num WHERE pni.isuse = 1 AND pni.pubId IN (SELECT pi.pubId FROM tb_public_num_info pni JOIN tb_public_info pi ON pi.pubId = pni.pubId AND pi.updateInfoTime < ? AND pni.isuse = 1 GROUP BY pi.pubId LIMIT 10)";
            /* SDK-478 huangzhiqiang 20160628 end */
            curResult = DBManager.rawQuery(sql, new String[] {  String.valueOf(updateStartTime) });
            needUpdateNumList = needUpdateNumList(curResult);
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager getNumsAppearInMonth: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }

        XyCursor.closeCursor(curResult, true);
        return needUpdateNumList;
    }

    /**
     * 需要批量更新的企业信息
     * 
     * @param curResult 必须包括num、versionCode、pubId、name、cmd、ec、nameType、mark_time、mark_cmd、mark_ec字段
     * @return
     * @throws JSONException
     */
    public static List<String> needUpdateNumList(XyCursor curResult) {
        if (curResult == null || curResult.getCount() == 0) {
            LogManager.w(Constant.TAG, "PubInfoManager needUpdateNumList: curResult is 0");
            return null;
        }
        try {
            List<String> dataList = new ArrayList<String>();
            while (curResult.moveToNext()) {
                JSONObject json = new JSONObject();
                json.put("num", curResult.getString(curResult.getColumnIndex("num")));
                json.put("version", curResult.getString(curResult.getColumnIndex("versionCode")));
                json.put("pubId", curResult.getString(curResult.getColumnIndex("pubId")));
                /* SDK-397 huangzhiqiang 20160524 start */
                json.put("name", curResult.getString(curResult.getColumnIndex("name"))); // 企业签名
                json.put("cmd", curResult.getString(curResult.getColumnIndex("cmd"))); // 退订指令
                /* SDK-478 huangzhiqiang 20160628 start */
                json.put("ec", curResult.getString(curResult.getColumnIndex("ec"))); // 行业编码
                /* SDK-478 huangzhiqiang 20160628 end */
                json.put("nameType", curResult.getInt(curResult.getColumnIndex("nameType"))); // 名称类型(0:企业名称  1:签名)
                json.put("markTime", curResult.getInt(curResult.getColumnIndex("mark_time"))); // 是否需要上传签名(0:不需要   1:需要)
                json.put("markCmd", curResult.getInt(curResult.getColumnIndex("mark_cmd"))); // 是否需要上传退订指令(0:不需要   1:需要)
                /* SDK-478 huangzhiqiang 20160628 start */
                json.put("markEC", curResult.getInt(curResult.getColumnIndex("mark_ec"))); // 是否需要上传行业编码(0:不需要   1:需要)
                /* SDK-478 huangzhiqiang 20160628 end */
                /* SDK-397 huangzhiqiang 20160524 end */
                dataList.add(json.toString());
            }
            return dataList;
        } catch (Exception ex) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager needUpdateNumList: ", ex);
            /*SDK-550 hewengao 20160719 end*/
        }
        return null;
    }

  /*  public static void updatePubInfoNum_LastLoadTime(String areaCode,ArrayList<String> numList) throws Exception {
        ContentValues values = new ContentValues();
        // 把更新时间重置为0
        values.put("lastloadtime", 0);
        Iterator<String> it = numList.iterator();
        while (it.hasNext()) {
            String str_json = it.next();
            JSONObject jo = new JSONObject(str_json);
            String num = jo.getString("num");
            if(!StringUtils.isNull(areaCode)){
                DBManager.update(PUB_NUM_INFO_TABLE_NAME, values, "num = ? and areaCode LIKE '%" + areaCode + "%'", new String[] { num });

            }else{
                DBManager.update(PUB_NUM_INFO_TABLE_NAME, values, "num = ?", new String[] { num });

            }
        }
    }*/

    public static JSONArray queryMenuDataAction(String pubId,  String num, String versionCode, String rid) {

        XyCursor cur = null;
        String companyNum = pubId + "_" + versionCode;
        try {
            cur = DBManager.query(PUB_MENU_INFO_TABLE_NAME, new String[] { "menuCode", "menuName", "menuType", "actionData" }, "pubId = ? ", new String[] { String.valueOf(pubId) }, null, null, " length(menuCode) ", null);
            if (cur == null) {
                return null;
            }
            String menuCode, menuName, menuType, actionData;
            HashMap<String, JSONObject> cacheData = new HashMap<String, JSONObject>();
            String nameKey = "name";
            String menuCodeKey = "menuCode";
            String typeKey = "type";
            String phoneNum = "phoneNum";
            String actionDataKey = "action_data";
            String secondMenuKey = "secondmenu";
            JSONArray jsonArr = new JSONArray();
            JSONObject jsonActionDataObject = new JSONObject();
            jsonActionDataObject.put("uiType", "MENU");
            jsonActionDataObject.put("phoneNum", num);
            jsonActionDataObject.put("companyNum", companyNum);
            jsonActionDataObject.put("rid", rid);

            HashSet<String> menuCodeSet = new HashSet<String>();
            while (cur.moveToNext()) {
                menuCode = cur.getString(0);
                if (menuCodeSet.contains(menuCode)) {
                    // PrintTestLogUtil.printTestLog("queryMenuDataAction",
                    // "已经包含了"+menuCode);
                    // 同一个menuCode，只会存在一个，出现多个，说明重复了。
                    continue;
                } else {
                    // PrintTestLogUtil.printTestLog("queryMenuDataAction",
                    // "还没有包含"+menuCode);
                    menuCodeSet.add(menuCode);
                }
                menuName = cur.getString(1);
                menuType = cur.getString(2);
                actionData = cur.getString(3);
//                jsonActionDataObject.put(nameKey, menuName);
                jsonActionDataObject.put(menuCodeKey, menuCode);
               

                if (actionData!=null){
                     jsonActionDataObject.put("menu_item_action_data", actionData);
                     actionData = jsonActionDataObject.toString();
                }
                if (menuCode.length() == 2) {
                    JSONObject jsonObject = null;
                    if (!"menu".equalsIgnoreCase(menuType)) {
                        jsonObject = JsonUtil.getJsonObject(nameKey, menuName, typeKey, menuType, actionDataKey, actionData);
                    } else {
                        jsonObject = JsonUtil.getJsonObject(nameKey, menuName, typeKey, menuType);
                        jsonObject.put(secondMenuKey, new JSONArray());
                        cacheData.put(menuCode, jsonObject);
                    }
                    if (jsonObject != null) {
                        jsonArr.put(jsonObject);
                    }
                } else if (menuCode.length() == 4) {
                    JSONObject jsonObject = JsonUtil.getJsonObject(nameKey, menuName, typeKey, menuType, actionDataKey, actionData);
                    JSONObject parentObj = cacheData.get(menuCode.substring(0, 2));
                    JSONArray secondjsonArr = parentObj.optJSONArray(secondMenuKey);
                    secondjsonArr.put(jsonObject);
                }
            }
            cacheData.clear();
            menuCodeSet.clear();
            return jsonArr;
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryMenuDataByPubId: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cur, true);
        }
        return null;
    }

    /**
     * 异步插入匹配规则，匹配的号码
     * 
     * @param pubId
     * @param areaCode
     * @param num
     * @param numType
     * @param purpose
     * @param extend
     * @param nameType
     */
    private static void asyncInsertRuleMatchNum(final int pubId, final String areaCode, final String num,
            final int numType, final String purpose, final String extend, final int nameType) {
        NetUtil.executeRunnable(new Runnable() {
            @Override
            public void run() {
                try {
                    /* SDK-397 huangzhiqiang 20160524 start */
                    ContentValues values = BaseManager.getContentValues(null, "pubId", String.valueOf(pubId),
                            "areaCode", areaCode, "num", num, "ptype", String.valueOf(numType), "lastloadtime",
                            String.valueOf(System.currentTimeMillis()), "isrulenum", "1", "purpose", purpose, "extend",
                            extend, "isuse", "1", "nameType", String.valueOf(nameType));
                    DBManager.saveOrUpdateTableData(PUB_NUM_INFO_TABLE_NAME, values, " num = ? and ptype = ? ",
                            new String[] { num, String.valueOf(numType) });
                    /* SDK-397 huangzhiqiang 20160524 end */

                    /* SDK-500 huangzhiqiang 20160621 start */
                    // NetQueryTimeManager.delNetQueryNum(num, areaCode);
                    /* SDK-500 huangzhiqiang 20160621 end */
                } catch (Throwable e) {
                    /*SDK-550 hewengao 20160719 start*/
                    LogManager.w(Constant.TAG, "PubInfoManager asyncInsertRuleMatchNum: ", e);
                    /*SDK-550 hewengao 20160719 end*/
                }
            }
        });
    }
    
    /**
     * 标记号码为使用过
     */
    private static void updateNumIsUse(final String num, final String areaCode) throws Exception{
    	/*NUBIA-297 wangbin 20170320 start */
         SmartSmsThreadPoolManager.pool.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    ContentValues values = new ContentValues();
                    values.put("isuse", "1");
                    int result = -1;
                    if(!StringUtils.isNull(areaCode)){
                        result = DBManager.update(PUB_NUM_INFO_TABLE_NAME, values, " num = ? and areaCode LIKE '%" + areaCode + "%'", new String[] { num});

                    }else{
                        result = DBManager.update(PUB_NUM_INFO_TABLE_NAME, values, " num = ? ", new String[] { num });

                    }

                    /* SDK-500 huangzhiqiang 20160621 start */
                    // NetQueryTimeManager.delNetQueryNum(num, areaCode);
                    /* SDK-500 huangzhiqiang 20160621 end */
                } catch (Throwable e) {
                    /*SDK-550 hewengao 20160719 start*/
                    LogManager.w(Constant.TAG, "PubInfoManager updateNumIsUse: ", e);
                    /*SDK-550 hewengao 20160719 end*/
                }
            }
        });
    	/*NUBIA-297 wangbin 20170320 end */
    }

   /* *//**
     * 更新号码的访问时间
     * 
     * @param num
     * @throws Throwable
     *//*
    private static void updateNumLoadTime(final String num, final String areaCode) throws Exception {
        NetUtil.executeRunnable(new Runnable() {
            @Override
            public void run() {
                try {
                    ContentValues values = new ContentValues();
                    values.put("lastloadtime", System.currentTimeMillis());
                    int result = -1;
                    if(!StringUtils.isNull(areaCode)){
                        result = DBManager.update(PUB_NUM_INFO_TABLE_NAME, values, " num = ? and areaCode LIKE '%" + areaCode + "%'", new String[] { num});

                    }else{
                        result = DBManager.update(PUB_NUM_INFO_TABLE_NAME, values, " num = ? ", new String[] { num });

                    }
                    LogManager.e("pubInfo", "updateNumLoadTime: " + num + " areaCode: " + areaCode+ "result ="+result);
                    NetQueryTimeManager.delNetQueryNum(num, areaCode);
                } catch (Throwable e) {
//                    e.printStackTrace();
                    LogManager.e(Constant.TAG, "PubInfoManager updateNumLoadTime: " +e.getMessage(), e);

                }
            }
        });
    }
*/
    /**
     * 描述：
     * 
     * @param ids
     * @return
     * @return ArrayList<String>
     */
    public static ArrayList<String> getPostBodyIdsList(String ids) {
        XyCursor curResult = null;

        try {

            ArrayList<String> list = new ArrayList<String>();
            String sql = "select DISTINCT versionCode, pubId from tb_public_info where  pubId  in ( " + ids + " )";

            curResult = DBManager.rawQuery(sql, null);
            if (curResult != null && curResult.getCount() > 0) {
                while (curResult.moveToNext()) {
                    String pubid = curResult.getString(curResult.getColumnIndex("pubId"));
                    String version = curResult.getString(curResult.getColumnIndex("versionCode"));
                    JSONObject json = new JSONObject();
                    json.put("num", pubid);// 解析的时候还是按照num解析的
                    json.put("version", version);
                    list.add(json.toString());
                }
                return list;
            }
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager getPostBodyIdsList: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(curResult, true);
        }

        return null;
    }

    public static void deleteRuleNumData() {
        try {
            DBManager.delete(PUB_NUM_INFO_TABLE_NAME, "isrulenum = 1", null);
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager deleteRuleNumData: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }

    public static HashMap<String, JSONObject> loadAllPubInfo(Set<String> pubIds) {
        if (pubIds == null || pubIds.isEmpty())
            return null;
        HashMap<String, JSONObject> publicInfoData = new HashMap<String, JSONObject>();
        XyCursor cur = null;
        try {
            StringBuffer sb = new StringBuffer();
            Iterator<String> it = pubIds.iterator();
            while (it.hasNext()) {
                String str = it.next();
                sb.append(str + ",");
            }
            sb.deleteCharAt(sb.length() - 1);
            /** HUAWEI-1190 zhengxiaobo begin */
            /* SDK-631 huangzhiqiang 20161008 start */
            String sql = "SELECT pubId,pubName,rectLogoName,classifyCode,circleLogoName,logoType,scale, backColor, backColorEnd from tb_public_info where pubId in  (" + sb.toString() + ")";
            /* SDK-631 huangzhiqiang 20161008 end */
            /** HUAWEI-1190 zhengxiaobo end */
            /*SDK-550 hewengao 20160719 start*/
            LogManager.d(Constant.TAG, "PubInfoManager loadAllPubInfo sql =",sql);
            /*SDK-550 hewengao 20160719 end*/
            cur = DBManager.rawQuery(sql, null);

            if (cur != null && cur.getCount() > 0) {
                int pubIdIndex = cur.getColumnIndex("pubId");
                int pubNameIndex = cur.getColumnIndex("pubName");
                int rectLogoNameIndex = cur.getColumnIndex("rectLogoName");
                int circleLogoNameIndex = cur.getColumnIndex("circleLogoName");
                /** HUAWEI-1190 zhengxiaobo begin */
                int classifyCodeIndex = cur.getColumnIndex("classifyCode");
                /** HUAWEI-1190 zhengxiaobo end */
                int logoTypeIndex = cur.getColumnIndex("logoType");
                /* SDK-631 huangzhiqiang 20161008 start */
                int scaleIndex = cur.getColumnIndex("scale");
                /* SDK-631 huangzhiqiang 20161008 end */
                
                /* SDK-704 zhaojiangweu 20161217 start */
                int bColorIndex = cur.getColumnIndex("backColor");
                int bColorEndIndex = cur.getColumnIndex("backColorEnd");
                /* SDK-704 zhaojiangweu 20161217 end */
                
                while (cur.moveToNext()) {
                    JSONObject pubInfo = new JSONObject();
                    String pubId = String.valueOf(cur.getInt(pubIdIndex));
                    pubInfo.put("id", pubId);
                    pubInfo.put("name", cur.getString(pubNameIndex));
                    /** HUAWEI-1190 zhengxiaobo begin */
                    pubInfo.put("classifyCode", cur.getString(classifyCodeIndex));
                    /** HUAWEI-1190 zhengxiaobo end */
                    pubInfo.put("logo", cur.getString(rectLogoNameIndex));
                    pubInfo.put("logoc", cur.getString(circleLogoNameIndex));
                    
                    /** SDK-524 zhaojiangwei 20160711 start */
                    pubInfo.put("logoType", cur.getString(logoTypeIndex));
                    /** SDK-524 zhaojiangwei 20160711  end */
                    /* SDK-631 huangzhiqiang 20161008 start */
                    pubInfo.put("scale", cur.getString(scaleIndex));
                    /* SDK-631 huangzhiqiang 20161008 end */
                    
                    /* SDK-704 huangzhiqiang 20161008 start */
                    pubInfo.put("backColor", cur.getString(bColorIndex));
                    pubInfo.put("backColorEnd", cur.getString(bColorEndIndex));
                    /* SDK-704 huangzhiqiang 20161008 end */
                    
                    publicInfoData.put(pubId, pubInfo);
                }

            }

        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager loadAllPubInfo: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cur, true);
        }
        return publicInfoData;
    }
    /**
     * 根据号码查询接入码类型企业id
     * @param phoneNumbers 号码
     * @return 
     */
    public static HashMap<String, String[]> loadAllPubNum(Set<String> phoneNumbers) {
        return loadAllPubNum(phoneNumbers,1);
    }
    /**
     * 根据号码和类型查询企业id
     * @param phoneNumbers 号码
     * @param ptype 类型
     * @return 
     */
    public static HashMap<String, String[]> loadAllPubNum(Set<String> phoneNumbers,  int ptype) {
        
        if (phoneNumbers == null || phoneNumbers.isEmpty())
            return null;
        HashMap<String, String[]> phonePublicIdData = new HashMap<String, String[]>();
        XyCursor cur = null;
        try {
            StringBuffer sb = new StringBuffer();
            Iterator<String> it = phoneNumbers.iterator();
            while (it.hasNext()) {
                String str = it.next();
                /*ONEPLUS-1607 songzhirong 20161022 start*/
                if(!StringUtils.isNumber(str)){
                	continue;
                }
                /*ONEPLUS-1607 songzhirong 20161022 end*/
                sb.append(str + ",");
            }
            sb.deleteCharAt(sb.length() - 1);

            /*SDK-495 zhaojiangwei 20160620 start*/
            Set<String> tmpCacheNums = new HashSet<String>();
            /* SDK-450 huangzhiqiang 20160624 start*/
            String areaCode = IccidLocationUtil.getAreaCodeByDefaultCard();
            /* SDK-450 huangzhiqiang 20160624 end*/
            if (StringUtils.isNull(areaCode)) {
                areaCode = "CN";
            }
            /*SDK-495 zhaojiangwei 20160620 end*/
            
            
            String sql = "SELECT pubId, num, purpose, areaCode from tb_public_num_info where num in  (" + sb.toString() + ") and ptype = " + ptype;
            /*SDK-550 hewengao 20160719 start*/
            LogManager.d(Constant.TAG, "PubInfoManager loadAllPubNum sql =", sql);
            /*SDK-550 hewengao 20160719 end*/
            cur = DBManager.rawQuery(sql, null);
            
            if (cur != null && cur.getCount() > 0) {
                 int pubIdIndex = cur.getColumnIndex("pubId");
                 int pubNumIndex = cur.getColumnIndex("num");
                 int purposeIndex = cur.getColumnIndex("purpose");
                 int areaCodeIndex = cur.getColumnIndex("areaCode");

                 while (cur.moveToNext()) {
                     String valPhoneNum = cur.getString(pubNumIndex);
                     String valPubId = cur.getString(pubIdIndex);
                     String valPurpose = cur.getString(purposeIndex);
                     /*SDK-495 zhaojiangwei 20160620 start*/
                     String valAreaCode = cur.getString(areaCodeIndex);
                    
                     if (tmpCacheNums.contains(valPhoneNum)) {
                         if (!valAreaCode.contains(areaCode)) {
                             continue;
                         }
                     }
                     phonePublicIdData.remove(valPhoneNum);
                     
                     /*SDK-449 zhaojiangwei 20160524 start*/
                     String[] dataValues = {valPubId,valPurpose};
                     phonePublicIdData.put(valPhoneNum, dataValues); //
                     tmpCacheNums.add(valPhoneNum);
                     /*SDK-449 zhaojiangwei 20160524 end*/
                     
                     /*SDK-495 zhaojiangwei 20160620 end*/
                }
            }
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager loadAllPubNum: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cur, true);
        }
        return phonePublicIdData;
    }

    /**
     * 根据公众号运营商返回符合要求的区域编码，如果没有传iccid和卡位但从缓存中找到匹配的区域则返回区域编码加ICCID（例:
     * GD_89860113851035985093），否则返回CN
     * 
     * @param numOperator 接入码对应的运营商编号(1:移动 2:联通 3:电信)
     * @param simIccid sim卡iccid
     * @param areaCode 当前区域编码
     * @param simIndex 用户选择的卡位
     * @return
     */
    private static String getAreaCodeByOperator(int numOperator, String simIccid, String areaCode, int simIndex) {
        if ("CN".equalsIgnoreCase(areaCode)) {
            return areaCode;
        }
        try {
            // 没有sim卡iccid和用户选择的卡位时遍历缓存的所有sim卡iccid对应区域编码数据，尝试找到与接入码拥有相同运营商的iccid对应的区域编码
            // 如果找到匹配数据则返回区域编码及ICCID（例:GD_89860113851035985093）
            if (StringUtils.isNull(simIccid) && simIndex < 0) {
                return compareOperatorByCache(numOperator);
            }

            // 没有sim卡iccid但存在用户选择的卡位信息，从数据库查询对应卡位数据，对比该卡位和接入码的运营商编号是否相同，
            // 如果相同且数据库内卡位对应的区域编码与当前区域编码相同，返回当前区域编码，否则返回CN
            if (StringUtils.isNull(simIccid) && simIndex >= 0) {
                return compareOperatorBySimIndex(numOperator, simIndex, areaCode);
            }

            // 存在sim卡iccid，对比sim卡iccid与接入码的运营商编号是否相同，如果相同返回当前区域编码，否则返回CN
            return compareOperatorByIccid(numOperator, simIccid, areaCode);
        } catch (Throwable ex) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager getAreaCodeByOperator: ", ex);
            /*SDK-550 hewengao 20160719 end*/
        }
        return "CN";
    }

    /**
     * 尝试从所有sim卡iccid对应区域编码缓存数据中找到与接入码拥有相同运营商编号的iccid对应的区域编码
     * 
     * @param numOperator 接入码对应的运营商编号(1:移动 2:联通 3:电信)
     * @return 返回与接入码拥有相同运营商编号的iccid对应的区域编码及ICCID（例:GD_89860113851035985093），
     *         无匹配数据则返回CN
     */
    private static String compareOperatorByCache(int numOperator) {
        HashMap<String, String[]> iccidAreaCodeMap = IccidLocationUtil.getIccidAreaCodeMap();
        if (iccidAreaCodeMap == null || iccidAreaCodeMap.isEmpty()) {
            return "CN";
        }
        Set<Entry<String, String[]>> setEntery = iccidAreaCodeMap.entrySet();
        for (Entry<String, String[]> entry : setEntery) {
            String[] iccidInfoArr = entry.getValue();

            int iccidOperator = getIccidOperatorNum(iccidInfoArr);
            if (iccidOperator == -2 || iccidOperator != numOperator) {
                continue;
            }

            /* SDK-485 huangzhiqiang 20160622 start */
            String userAreaCode = iccidInfoArr[3];
            if (!StringUtils.isNull(userAreaCode)) {
                return userAreaCode + "_" + entry.getKey();
            }
            String simAreaCode = iccidInfoArr[0];
            if (!StringUtils.isNull(simAreaCode)) {
                return simAreaCode + "_" + entry.getKey();
            }
            /* SDK-485 huangzhiqiang 20160622 end */
        }
        return "CN";
    }

    /**
     * 从数据库查询对应卡位数据，对比该卡位和接入码的运营商编号是否相同，
     * 如果相同且数据库内卡位对应的区域编码与当前区域编码相同，返回当前区域编码，否则返回CN
     * 
     * @param numOperator
     * @param simIndex
     * @param areaCode
     * @return
     */
    private static String compareOperatorBySimIndex(int numOperator, int simIndex, String areaCode) {
        if (StringUtils.isNull(areaCode) || "CN".equalsIgnoreCase(areaCode)) {
            return "CN";
        }
        /*SDK-550 hewengao 20160719 start*/
        if (simIndex < 0) {
            return "CN";
        }

        IccidInfo iccidInfo = IccidInfoManager.queryIccidInfo(null, simIndex);
        if (iccidInfo == null) {
            return "CN";
        }

        String strNumOperator = String.valueOf(numOperator);
        String userAreaCode = iccidInfo.userAreacode;
        String userOperator = IccidLocationUtil.getOperatorNum(null, iccidInfo.userOperator);
        /* SDK-485 huangzhiqiang 20160622 start */
        if (!StringUtils.isNull(userAreaCode)) {
            if (areaCode.equalsIgnoreCase(userAreaCode) && strNumOperator.equals(userOperator)) {
                return areaCode;
            }
        } else {
            String simIndexAreaCode = iccidInfo.areaCode;
            String simIndexOperator = IccidLocationUtil.getOperatorNum(null, iccidInfo.operator);
            if (areaCode.equalsIgnoreCase(simIndexAreaCode) && strNumOperator.equals(simIndexOperator)) {
                return areaCode;
            }
        }
        /* SDK-485 huangzhiqiang 20160622 end */
        /*SDK-550 hewengao 20160719 end*/
         return "CN";
    }

    /**
     * 对比sim卡iccid与接入码的运营商编号是否相同，如果相同返回当前区域编码，否则返回CN
     * 
     * @param simIccid
     *            sim卡iccid
     * @param areaCode
     *            当前区域编码
     * @return
     */
    private static String compareOperatorByIccid(int numOperator, String simIccid, String areaCode) {
        // 优先获取用户选择的运营商编号或接口识别的运营商编号
        int iccidOperator = getIccidOperatorNum(IccidLocationUtil.getIccidInfoArr(simIccid));
        if (iccidOperator == -2) {
            // 缓存的运营商编号为未知或没有该iccid的缓存数据，通过本地方法获取运营商编号
            iccidOperator = IccidLocationUtil.getOperatorByICCID(simIccid);
        }
        /*SDK-550 hewengao 20160719 start*/
        if (iccidOperator != -2 && iccidOperator == numOperator) {
             return areaCode;
        }
        /*SDK-550 hewengao 20160719 end*/
        return "CN";
    }

    /**
     * 获取iccid的运营商编号
     * 
     * @param iccidInfoArr
     *            sim卡iccid信息集合【index0:所属区域编码 index1:数据更新时间 index2:所属运营商编号
     *            index3:用户设置的区域编码 index4:用户设置的运营商编号】其中运营商编号为(1:移动 2:联通 3:电信
     *            -2:未知)
     * @return
     */
    private static int getIccidOperatorNum(String[] iccidInfoArr) {
        if (iccidInfoArr == null || iccidInfoArr.length == 0) {
            return -2;
        }
        try {
            int userOperatorNum = -2;
            if (iccidInfoArr.length > 4 && !StringUtils.isNull(iccidInfoArr[4])) {
                try {
                    userOperatorNum = Integer.parseInt(iccidInfoArr[4]);
                    if (userOperatorNum != -2) {
                        // 用户设置的运营商编号不为未知时优先返回用户设置的运营商编号
                        return userOperatorNum;
                    }
                } catch (Throwable ex) {
                }
            }

            if (iccidInfoArr.length > 2 && !StringUtils.isNull(iccidInfoArr[2])) {
                try {
                    // 返回接口识别的运营商编号
                    return Integer.parseInt(iccidInfoArr[2]);
                } catch (Throwable ex) {
                }
            }
        } catch (Throwable ex) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager getIccidOperatorNum: ", ex);
            /*SDK-550 hewengao 20160719 end*/
        }
        return -2;
    }

    /**
     * 获取公众号对应的运营商编号(1:移动 2:联通 3:电信 -2:未知)
     * 
     * @param pubInfoMap
     * @return 返回运营商编号，无extend数据或出现异常时返回-1
     */
    public static int getPubInfoOperatorNum(HashMap<String, String> pubInfoMap) {
        if (pubInfoMap == null) {
            return -1;
        }
        return getOperatorNumByExtend(pubInfoMap.get("extend"));
    }

    /**
     * 从extend获取公众号对应的运营商编号(1:移动 2:联通 3:电信 -2:未知)
     * 
     * @param extend
     *            json格式{"sp":"1|2|3"}
     * @return
     */
    private static int getOperatorNumByExtend(String extend) {
        // extend数据为null或extend内保存的不是JSONObject字符串直接返回-1
        if (extend == null || extend.indexOf("{") == -1) {
            return -1;
        }
        try {
            JSONObject operatorJson = new JSONObject(extend);
            return operatorJson.getInt("sp");
        } catch (Throwable ex) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager getOperatorNumByExtend 公众号运营商信息转JSONObject异常", ex);
            /*SDK-550 hewengao 20160719 end*/
        }
        return -1;
    }

    /**
     * 根据公众号获取公众号对应的运营商编号(1:移动 2:联通 3:电信 -2:未知)
     * 
     * @param pubId
     * @return
     */
    public static int getOperatorNumByPubNum(String pubNum) {
        if (StringUtils.isNull(pubNum)) {
            return -1;
        }
        XyCursor cur = null;
        try {
            String sql = "SELECT extend FROM tb_public_num_info WHERE num = ? LIMIT 1";
            cur = DBManager.rawQuery(sql, new String[] { pubNum });
            if (cur == null || cur.getCount() < 1) {
                return -1;
            }

            String extend = null;
            if (cur.moveToNext()) {
                extend = cur.getString(0);
            }
            return getOperatorNumByExtend(extend);
        } catch (Throwable ex) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager getOperatorNumByPubNum 根据公众号获取公众号对应的运营商编号异常", ex);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cur, true);
        }
        return -1;
    }

    /**
     * 字符串卡位转int类型卡位
     * 
     * @param simIndexStr
     * @return
     */
    public static int parseSimIndex(String simIndexStr) {
        if (StringUtils.isNull(simIndexStr)) {
            return -1;
        }
        int simIndex = -1;
        try {
            simIndex = Integer.parseInt(simIndexStr);
        } catch (Throwable ex) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager parseSimIndex 无效的卡位,simIndexStr", ex);
            /*SDK-550 hewengao 20160719 start*/
        }
        return simIndex;
    }
    
    public static final String QUERY_TRAFFIC = "queryTraffic";
    public static final String QUERY_CHARGE = "queryCharge";
    public static final String SELECT_SIM_CARD = "selectSimCard";

    /**
     * 找出查流量及查话费菜单数据
     * 
     * @param menuData
     * @return
     */
    public static String findQueryTrafficAndChargeActionData(String menuData) {
        if (StringUtils.isNull(menuData) || !menuData.contains("action_data")) {
            return null;
        }
        JSONObject queryTrafficAndChargeMenuData = new JSONObject();
        try {
            JSONArray menuDataArr = new JSONArray(menuData);
            int len = menuDataArr.length();
            boolean isSaveMenuData = false;
            for (int i = 0; i < len; i++) {
                JSONObject dataObj = menuDataArr.getJSONObject(i);
                // 没有二级菜单的直接跳过
                if (!dataObj.has("secondmenu")) {
                    continue;
                }
                JSONArray secondMenuDataArr = dataObj.getJSONArray("secondmenu");
                // 二级菜单没有数据的直接跳过
                if (secondMenuDataArr.length() == 0) {
                    continue;
                }
                int secondDataLen = secondMenuDataArr.length();
                for (int j = 0; j < secondDataLen; j++) {
                    JSONObject secondDataObj = secondMenuDataArr.getJSONObject(j);
                    String menuItemName = secondDataObj.getString("name");
                    if (menuItemName.contains("查") && menuItemName.contains("流量")) {
                        queryTrafficAndChargeMenuData.put(QUERY_TRAFFIC, secondDataObj);
                        continue;
                    }
                    if ((menuItemName.contains("查") && menuItemName.contains("话费")) 
                            || (menuItemName.contains("查") && menuItemName.contains("余额"))) {
                        queryTrafficAndChargeMenuData.put(QUERY_CHARGE, secondDataObj);
                    }
                    // 已保存查流量及查话费菜单数据后结束循环
                    if (queryTrafficAndChargeMenuData.has(QUERY_TRAFFIC)
                            && queryTrafficAndChargeMenuData.has(QUERY_CHARGE)) {
                        isSaveMenuData = true;
                        break;
                    }
                }
                // 已保存查流量及查话费菜单数据后结束循环
                if (isSaveMenuData) {
                    break;
                }
            }
        } catch (Throwable t) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.e(Constant.TAG, "PubInfoManager findQueryTrafficAndChargeActionData: ", t);
            /*SDK-550 hewengao 20160719 end*/
        }
        return queryTrafficAndChargeMenuData.length() == 0 ? null : queryTrafficAndChargeMenuData.toString();
    }

    /**
     * 添加查流量及查话费的菜单数据到全国菜单
     * 
     * @param menuDataCN 全国菜单数据
     * @param iccid2MenuActionDataMap 所有SIM卡的查流量、查话费菜单数据
     * @return
     */
    public static String addQueryTrafficAndChargeToMenuData(String menuDataCN, Map<String, String> iccid2MenuActionDataMap) {
        if (StringUtils.isNull(menuDataCN) 
                || !menuDataCN.contains("action_data")
                || iccid2MenuActionDataMap == null
                || iccid2MenuActionDataMap.isEmpty() ) {
            return null;
        }
        JSONArray menuData = null;
        try {
            menuData = new JSONArray(menuDataCN);
            
            JSONObject firstMenuDate = menuData.getJSONObject(0);
            // 更改菜单名为“业务办理”
            firstMenuDate.put("name", "业务办理");
            
            // 拿到第一个菜单的二级菜单
            JSONArray secondMenuDataArr = firstMenuDate.getJSONArray("secondmenu");
            // 添加查流量及查话费二级菜单到第一个菜单
            Set<Entry<String, String>> setEntery = iccid2MenuActionDataMap.entrySet();
            for (Entry<String, String> entry : setEntery) {
                JSONObject actionDate = new JSONObject(entry.getValue());
                JSONObject menuItem = actionDate.optJSONObject(QUERY_TRAFFIC);
                if (menuItem != null) {
                    secondMenuDataArr.put(JsonUtil.getJsonObject("name", menuItem.getString("name"), "type", SELECT_SIM_CARD,
                            "actionType", QUERY_TRAFFIC));
                }
                menuItem = actionDate.optJSONObject(QUERY_CHARGE);
                if (menuItem != null) {
                    secondMenuDataArr.put(JsonUtil.getJsonObject("name", menuItem.getString("name"), "type", SELECT_SIM_CARD,
                            "actionType", QUERY_CHARGE));
                }
                // 只需要生成一次查流量及查话费二级菜单
                break;
            }
        } catch (Throwable t) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager addQueryTrafficAndChargeToMenuData: ", t);
            /*SDK-550 hewengao 20160719 end*/
        }
        return menuData == null ? null : menuData.toString();
    }
    
    public static void updateUpdateInfoTime(List<String> list){
        /*SDK-550 hewengao 20160719 start*/
        try {
                if(list == null || list.isEmpty()) return;
                StringBuffer sb = new StringBuffer();
                for (String jsonStr : list) {
                    JSONObject jsonObject = new JSONObject(jsonStr);
                    String pubId = jsonObject.optString("pubId");    
                    if(StringUtils.isNull(pubId)){
                        continue;
                    }
                    sb.append(","+pubId);     
                }
                
                if(sb.length()<=0)return;
                final String str = sb.substring(1);
                sb.setLength(0);
                String sql = "UPDATE " + PUB_INFO_TABLE_NAME + " SET updateInfoTime = "+System.currentTimeMillis()+" WHERE pubId IN ("+str+")";
                DBManager.execSQL(sql);
        } catch (Throwable e) {
            LogManager.w(Constant.TAG, "PubInfoManager updateUpdateInfoTime: ", e);
        }
        /*SDK-550 hewengao 20160719 end*/
    }

    /* SDK-397 huangzhiqiang 20160526 start */
    /**
     * 获号码对应的名称类型
     * 
     * @param num
     * @param areaCode
     * @return 0:企业名称  1:签名  -1:未知
     */
    public static int getNameType(String num, String areaCode) {
        int nameType = -1;
        try {
            if (StringUtils.isNull(areaCode)) {
                areaCode = "CN";
            }
            nameType = queryNameTypeByNumAndAreaCode(num, areaCode);
            if (nameType == -1 && !"CN".equalsIgnoreCase(areaCode)) {
                nameType = queryNameTypeByNumAndAreaCode(num, "CN");
            }
            return nameType;
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager getNameType: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
        return -1;
    }

    /**
     * 根据号码及区域获取号码签名类型
     * 
     * @param num
     * @param areaCode
     * @return  0:企业名称  1:签名  -1:未知
     */
    private static int queryNameTypeByNumAndAreaCode(String num, String areaCode){
        XyCursor cursor = null;
        try {
            String sql = "SELECT DISTINCT nameType FROM tb_public_num_info WHERE num =? AND areaCode LIKE ?";
            cursor = DBManager.rawQuery(sql, new String[] { num, "%" + areaCode + "%" });
            if (cursor != null && cursor.getCount() > 0 && cursor.moveToNext()) {
                return cursor.getInt(0);
            }
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager queryNameTypeByNumAndAreaCode: ", e);
            /*SDK-550 hewengao 20160719 end*/
        } finally {
            XyCursor.closeCursor(cursor, true);
        }
        return -1;
    }

    /**
     * 如果公众号的名称是签名名称，判断是否有效公众号数据
     * 
     * @param pubInfo
     * @return
     */
    public static boolean checkIsEffectivePubInfoIfNameTypeIsSign(JSONObject pubInfo) {
        // 企业信息为null则为无效公众号数据
        if (pubInfo == null) {
            return false;
        }

        // 名称类型不是签名名称，识别为有效数据
        if (!nameTypeIsSign(pubInfo.optInt("nameType"))) {
            return true;
        }

        // 名称类型为签名名称，需要校验当前企业签名与最新企业签名是否匹配，不匹配则代表为无效数据
        String num =  StringUtils.getPhoneNumberNo86(pubInfo.optString("num"));
        int pubId = pubInfo.optInt("pubId");
        // 企业签名匹配或无最新签名数据，识别为有效数据
        if(!numSignNotMatch(num, pubId)){
            return true;
        }

        // 前企业签名与最新企业签名不匹配，识别为无效数据
        return false;
    }

    /**
     * 是否需要更新公众号信息
     * 
     * @param pubInfo
     * @return
     */
    public static boolean needUpdatePubInfo(JSONObject pubInfo) {
        if (pubInfo == null) {
            return false;
        }

        // 名称类型不是签名名称，不需要更新公众号信息
        if (!nameTypeIsSign(pubInfo.optInt("nameType"))) {
            return false;
        }

        String num = StringUtils.getPhoneNumberNo86(pubInfo.optString("num"));
        NumName numInfo = NumNameManager.queryDataByNum(num, false);
        // 没有最新签名数据，不需要更新公众号信息
        if (numInfo == null || numInfo.lastNamePubId == 0) {
            return false;
        }

        // 已查询过签名且未过查询周期，不需要更新公众号信息
        if (!NumNameManager.canQuerySignInfo(numInfo.lastQueryTime)) {
            return false;
        }

        // 当前名称与最新签名相同，不需要更新公众号信息
        if (numInfo.lastNamePubId == pubInfo.optInt("pubId")) {
            return false;
        }

        // 更新最后查询时间及签名上传标志为1（1代表需要上传签名），目的是让公众号信息查询报文带上签名信息
        NumNameManager.updateLastQueryTimeAndMark(pubInfo.optString("num"), System.currentTimeMillis(), 1);
        
        // 是签名企业并且当前企业ID与最新签名的企业ID不同，需要更新公众号信息
        return true;
    }

    /**
     * 名称类型为签名名称
     * 
     * @param nameType
     * @return true:是签名名称 false:非签名名称
     */
    private static boolean nameTypeIsSign(int nameType){
        if (nameType == PubInfoManager.NAME_TYPE_SIGN) {
            return true;
        }
        return false;
    }

    /**
     * 当前企业签名与最新企业签名不匹配
     * 
     * @param num 企业号码，用于获取最新企业签名
     * @param pubId 企业号码对应的企业ID，用于与最新企业ID对比
     * @return true:企业签名不匹配 false:企业签名匹配或无最新签名数据
     */
    private static boolean numSignNotMatch(String num, int pubId) {
        NumName numInfo = NumNameManager.queryDataByNum(num, false);
        // 没有最新签名数据
        if (numInfo == null || numInfo.lastNamePubId == 0) {
            return false;
        }

        // 当前企业ID与最新签名的企业ID相同
        if (pubId == numInfo.lastNamePubId) {
            return false;
        }

        // 当前企业ID与最新签名的企业ID不同
        return true;
    }
    /* SDK-397 huangzhiqiang 20160526 end */
    
    /*SDK-727 zhaojiangwei 20170227 start */
    public static void clearItemsWithoutBackColor(){
        try {
            DBManager.execSQL("delete from tb_public_info where backColor is null and backColorEnd is null");
        } catch (Throwable e) {
            /*SDK-550 hewengao 20160719 start*/
            LogManager.w(Constant.TAG, "PubInfoManager clearItemsWithoutbackColor: ", e);
            /*SDK-550 hewengao 20160719 end*/
        }
    }
    /*SDK-727 zhaojiangwei 20170227 end */
}
